using Circus.CodeEditor;
using Circus.CodeEditor.TextSource;
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Circus.CodeEditor.Dialogs
{
	public class DlgModalSearch : Form
	{
		private const int defaultOptionsHeigth = 93;
		private const int defaultOptionsReplaceHeigth = 110;
		private const int defaultFormHeigth = 256;
		private const int defaultFormReplaceHeigth = 299;
		private const int defaultPanelOffset = 3;
		private const int defaultGroupOffset = 3;
		private const int defaultButtonOffset = 5;
		private const int defaultDirectionHeigth = 58;
		private const string defaultFindText = "Find Text";
		private const string defaultReplaceText = "Find Text";
		private IContainer components = null;
		private ImageList imSearch;
		private Panel pnFind;
		private Panel pnReplace;
		public Label laFindWhat;
		public ComboBox cbFindWhat;
		public ComboBox cbReplaceWith;
		public Label laReplaceWith;
		private GroupBox gbOptions;
		private GroupBox gbScope;
		private GroupBox gbDirection;
		private GroupBox gbOrigin;
		public CheckBox chbPromptOnReplace;
		public CheckBox chbSearchHiddenText;
		public CheckBox chbRegularExpressions;
		public CheckBox chbWholeWordsOnly;
		public CheckBox chbCaseSensitive;
		public RadioButton rbSelectedText;
		public RadioButton rbCurrentDocument;
		public RadioButton rbBackward;
		public RadioButton rbForward;
		public RadioButton rbEntireScope;
		public RadioButton rbFromCursor;
		private Panel panel1;
		public Button btCancel;
		public Button btReplaceAll;
		public Button btOk;
		public RadioButton rbAllOpenDocuments;
		public RadioButton rbCurrentProject;
		private bool isReplace;
		private CodeEditor search;
		private SearchOptions options;
		private bool clearBookmarks;
		private bool firstSearch = true;
		private SearchOptions saveOptions;
		private string saveText = string.Empty;
		private bool optionsVisible = false;
		private bool selectionEnabled = false;
		protected int baseOptionsHeight = 0;
		private int baseHeight = 0;
		protected virtual bool FirstSearch
		{
			get
			{
				return this.SearchShared ? SearchManager.SharedSearch.FirstSearch : this.search.FirstSearch;
			}
		}
		protected virtual bool SearchShared
		{
			get
			{
				return SearchManager.SharedSearch.Shared;
			}
			set
			{
				SearchManager.SharedSearch.Shared = value;
				SearchManager.SharedSearch.Init(ref this.search, this.Options);
			}
		}
		public CodeEditor Search
		{
			get
			{
				return this.SearchShared ? SearchManager.SharedSearch.Search : this.search;
			}
			set
			{
				this.search = value;
			}
		}
		public SearchOptions Options
		{
			get
			{
				SearchOptions searchOptions = (this.chbCaseSensitive.Checked ? SearchOptions.CaseSensitive : SearchOptions.None) | (this.chbWholeWordsOnly.Checked ? SearchOptions.WholeWordsOnly : SearchOptions.None) | (this.chbSearchHiddenText.Checked ? SearchOptions.SearchHiddenText : SearchOptions.None) | (this.chbRegularExpressions.Checked ? SearchOptions.RegularExpressions : SearchOptions.None) | (this.chbPromptOnReplace.Checked ? SearchOptions.PromptOnReplace : SearchOptions.None) | (this.rbAllOpenDocuments.Checked ? SearchOptions.AllDocuments : SearchOptions.None) | (this.rbCurrentProject.Checked ? SearchOptions.CurrentProject : SearchOptions.None) | (((this.options & SearchOptions.FindSelectedText) != SearchOptions.None) ? SearchOptions.FindSelectedText : SearchOptions.None) | (((this.options & SearchOptions.CycledSearch) != SearchOptions.None) ? SearchOptions.CycledSearch : SearchOptions.None) | (((this.options & SearchOptions.SilentSearch) != SearchOptions.None) ? SearchOptions.SilentSearch : SearchOptions.None);
				searchOptions |= (this.rbBackward.Checked ? SearchOptions.BackwardSearch : SearchOptions.None);
				searchOptions |= (this.rbEntireScope.Checked ? SearchOptions.EntireScope : SearchOptions.None);
				searchOptions |= (this.rbFromCursor.Checked ? SearchOptions.FindTextAtCursor : SearchOptions.None);
				if (this.search != null)
				{
					this.search.SearchGlobal = (this.rbAllOpenDocuments.Checked || this.rbCurrentProject.Checked);
				}
				SearchManager.SharedSearch.SearchSettings.GlobalSearch = this.search.SearchGlobal;
				if (this.rbSelectedText.Checked)
				{
					searchOptions |= SearchOptions.SelectionOnly;
				}
				if (this.rbCurrentProject.Checked)
				{
					searchOptions |= SearchOptions.CurrentProject;
				}
				if (this.rbAllOpenDocuments.Checked)
				{
					searchOptions |= SearchOptions.AllDocuments;
				}
				if (this.rbCurrentProject.Checked)
				{
					searchOptions |= SearchOptions.CurrentProject;
				}
				return searchOptions;
			}
			set
			{
				this.options = value;
				this.chbCaseSensitive.Checked = ((value & SearchOptions.CaseSensitive) != SearchOptions.None);
				this.chbWholeWordsOnly.Checked = ((value & SearchOptions.WholeWordsOnly) != SearchOptions.None);
				this.chbSearchHiddenText.Checked = ((value & SearchOptions.SearchHiddenText) != SearchOptions.None);
				this.chbRegularExpressions.Checked = ((value & SearchOptions.RegularExpressions) != SearchOptions.None);
				this.chbPromptOnReplace.Checked = ((value & SearchOptions.PromptOnReplace) != SearchOptions.None);
				this.rbBackward.Checked = ((value & SearchOptions.BackwardSearch) != SearchOptions.None);
				this.rbForward.Checked = ((value & SearchOptions.BackwardSearch) == SearchOptions.None);
				this.rbEntireScope.Checked = ((value & SearchOptions.EntireScope) != SearchOptions.None);
				this.rbFromCursor.Checked = ((value & SearchOptions.FindTextAtCursor) != SearchOptions.None);
				this.rbCurrentDocument.Checked = true;
				bool globalSearch = SearchManager.SharedSearch.SearchSettings.GlobalSearch;
				this.rbAllOpenDocuments.Checked = ((value & SearchOptions.AllDocuments) != SearchOptions.None);
				this.rbCurrentProject.Checked = ((value & SearchOptions.CurrentProject) != SearchOptions.None);
				this.rbSelectedText.Checked = (!globalSearch && (value & SearchOptions.SelectionOnly) != SearchOptions.None);
			}
		}
		public bool SelectionEnabled
		{
			get
			{
				return this.selectionEnabled;
			}
			set
			{
				this.selectionEnabled = value;
			}
		}
		public bool IsReplace
		{
			get
			{
				return this.isReplace;
			}
			set
			{
				if (this.isReplace != value)
				{
					this.isReplace = value;
					this.ReplaceChanged();
				}
			}
		}
		public bool OptionsVisible
		{
			get
			{
				return this.optionsVisible;
			}
			set
			{
				this.optionsVisible = value;
			}
		}
		public bool ClearBookmarks
		{
			get
			{
				return this.clearBookmarks;
			}
			set
			{
				this.clearBookmarks = value;
			}
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.components = new Container();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(DlgModalSearch));
			this.imSearch = new ImageList(this.components);
			this.pnFind = new Panel();
			this.laFindWhat = new Label();
			this.cbFindWhat = new ComboBox();
			this.pnReplace = new Panel();
			this.cbReplaceWith = new ComboBox();
			this.laReplaceWith = new Label();
			this.gbOptions = new GroupBox();
			this.chbPromptOnReplace = new CheckBox();
			this.chbSearchHiddenText = new CheckBox();
			this.chbRegularExpressions = new CheckBox();
			this.chbWholeWordsOnly = new CheckBox();
			this.chbCaseSensitive = new CheckBox();
			this.gbScope = new GroupBox();
			this.rbCurrentProject = new RadioButton();
			this.rbAllOpenDocuments = new RadioButton();
			this.rbSelectedText = new RadioButton();
			this.rbCurrentDocument = new RadioButton();
			this.gbDirection = new GroupBox();
			this.rbBackward = new RadioButton();
			this.rbForward = new RadioButton();
			this.gbOrigin = new GroupBox();
			this.rbEntireScope = new RadioButton();
			this.rbFromCursor = new RadioButton();
			this.panel1 = new Panel();
			this.btCancel = new Button();
			this.btReplaceAll = new Button();
			this.btOk = new Button();
			this.pnFind.SuspendLayout();
			this.pnReplace.SuspendLayout();
			this.gbOptions.SuspendLayout();
			this.gbScope.SuspendLayout();
			this.gbDirection.SuspendLayout();
			this.gbOrigin.SuspendLayout();
			this.panel1.SuspendLayout();
			base.SuspendLayout();
			this.imSearch.ImageStream = (ImageListStreamer)componentResourceManager.GetObject("imSearch.ImageStream");
			this.imSearch.TransparentColor = Color.Fuchsia;
			this.imSearch.Images.SetKeyName(0, "UseFind1.bmp");
			this.imSearch.Images.SetKeyName(1, "UseReplace1.bmp");
			this.pnFind.Controls.Add(this.laFindWhat);
			this.pnFind.Controls.Add(this.cbFindWhat);
			this.pnFind.Dock = DockStyle.Top;
			this.pnFind.Location = new Point(0, 0);
			this.pnFind.Name = "pnFind";
			this.pnFind.Size = new Size(360, 31);
			this.pnFind.TabIndex = 19;
			this.laFindWhat.AutoSize = true;
			this.laFindWhat.FlatStyle = FlatStyle.System;
			this.laFindWhat.Location = new Point(8, 9);
			this.laFindWhat.Name = "laFindWhat";
			this.laFindWhat.Size = new Size(63, 13);
			this.laFindWhat.TabIndex = 22;
			this.laFindWhat.Text = "&Text to find:";
			this.cbFindWhat.Location = new Point(86, 7);
			this.cbFindWhat.Name = "cbFindWhat";
			this.cbFindWhat.Size = new Size(266, 21);
			this.cbFindWhat.TabIndex = 23;
			this.pnReplace.Controls.Add(this.cbReplaceWith);
			this.pnReplace.Controls.Add(this.laReplaceWith);
			this.pnReplace.Dock = DockStyle.Top;
			this.pnReplace.Location = new Point(0, 31);
			this.pnReplace.Name = "pnReplace";
			this.pnReplace.Size = new Size(360, 25);
			this.pnReplace.TabIndex = 20;
			this.cbReplaceWith.Location = new Point(86, 1);
			this.cbReplaceWith.Name = "cbReplaceWith";
			this.cbReplaceWith.Size = new Size(266, 21);
			this.cbReplaceWith.TabIndex = 26;
			this.cbReplaceWith.Visible = false;
			this.laReplaceWith.AutoSize = true;
			this.laReplaceWith.FlatStyle = FlatStyle.System;
			this.laReplaceWith.Location = new Point(8, 5);
			this.laReplaceWith.Name = "laReplaceWith";
			this.laReplaceWith.Size = new Size(72, 13);
			this.laReplaceWith.TabIndex = 25;
			this.laReplaceWith.Text = "&Replace with:";
			this.laReplaceWith.Visible = false;
			this.gbOptions.Controls.Add(this.chbPromptOnReplace);
			this.gbOptions.Controls.Add(this.chbSearchHiddenText);
			this.gbOptions.Controls.Add(this.chbRegularExpressions);
			this.gbOptions.Controls.Add(this.chbWholeWordsOnly);
			this.gbOptions.Controls.Add(this.chbCaseSensitive);
			this.gbOptions.Location = new Point(8, 56);
			this.gbOptions.Name = "gbOptions";
			this.gbOptions.Size = new Size(168, 105);
			this.gbOptions.TabIndex = 21;
			this.gbOptions.TabStop = false;
			this.gbOptions.Text = "Options";
			this.chbPromptOnReplace.AutoSize = true;
			this.chbPromptOnReplace.Checked = true;
			this.chbPromptOnReplace.CheckState = CheckState.Checked;
			this.chbPromptOnReplace.Location = new Point(8, 85);
			this.chbPromptOnReplace.Name = "chbPromptOnReplace";
			this.chbPromptOnReplace.Size = new Size(112, 17);
			this.chbPromptOnReplace.TabIndex = 4;
			this.chbPromptOnReplace.Text = "&Prompt on replace";
			this.chbPromptOnReplace.UseVisualStyleBackColor = true;
			this.chbSearchHiddenText.AutoSize = true;
			this.chbSearchHiddenText.Checked = true;
			this.chbSearchHiddenText.CheckState = CheckState.Checked;
			this.chbSearchHiddenText.Location = new Point(8, 68);
			this.chbSearchHiddenText.Name = "chbSearchHiddenText";
			this.chbSearchHiddenText.Size = new Size(115, 17);
			this.chbSearchHiddenText.TabIndex = 3;
			this.chbSearchHiddenText.Text = "Search &hidden text";
			this.chbSearchHiddenText.UseVisualStyleBackColor = true;
			this.chbRegularExpressions.AutoSize = true;
			this.chbRegularExpressions.Location = new Point(8, 51);
			this.chbRegularExpressions.Name = "chbRegularExpressions";
			this.chbRegularExpressions.Size = new Size(121, 17);
			this.chbRegularExpressions.TabIndex = 2;
			this.chbRegularExpressions.Text = "Regular e&xpressions";
			this.chbRegularExpressions.UseVisualStyleBackColor = true;
			this.chbWholeWordsOnly.AutoSize = true;
			this.chbWholeWordsOnly.Location = new Point(8, 34);
			this.chbWholeWordsOnly.Name = "chbWholeWordsOnly";
			this.chbWholeWordsOnly.Size = new Size(110, 17);
			this.chbWholeWordsOnly.TabIndex = 1;
			this.chbWholeWordsOnly.Text = "&Whole words only";
			this.chbWholeWordsOnly.UseVisualStyleBackColor = true;
			this.chbCaseSensitive.AutoSize = true;
			this.chbCaseSensitive.Location = new Point(8, 17);
			this.chbCaseSensitive.Name = "chbCaseSensitive";
			this.chbCaseSensitive.Size = new Size(94, 17);
			this.chbCaseSensitive.TabIndex = 0;
			this.chbCaseSensitive.Text = "Case sensitive";
			this.chbCaseSensitive.UseVisualStyleBackColor = true;
			this.gbScope.Controls.Add(this.rbCurrentProject);
			this.gbScope.Controls.Add(this.rbAllOpenDocuments);
			this.gbScope.Controls.Add(this.rbSelectedText);
			this.gbScope.Controls.Add(this.rbCurrentDocument);
			this.gbScope.Location = new Point(184, 56);
			this.gbScope.Name = "gbScope";
			this.gbScope.Size = new Size(168, 105);
			this.gbScope.TabIndex = 22;
			this.gbScope.TabStop = false;
			this.gbScope.Text = "Scope";
			this.rbCurrentProject.AutoSize = true;
			this.rbCurrentProject.Location = new Point(8, 68);
			this.rbCurrentProject.Name = "rbCurrentProject";
			this.rbCurrentProject.Size = new Size(94, 17);
			this.rbCurrentProject.TabIndex = 3;
			this.rbCurrentProject.TabStop = true;
			this.rbCurrentProject.Text = "Current project";
			this.rbCurrentProject.UseVisualStyleBackColor = true;
			this.rbAllOpenDocuments.AutoSize = true;
			this.rbAllOpenDocuments.Location = new Point(8, 51);
			this.rbAllOpenDocuments.Name = "rbAllOpenDocuments";
			this.rbAllOpenDocuments.Size = new Size(118, 17);
			this.rbAllOpenDocuments.TabIndex = 2;
			this.rbAllOpenDocuments.TabStop = true;
			this.rbAllOpenDocuments.Text = "All open documents";
			this.rbAllOpenDocuments.UseVisualStyleBackColor = true;
			this.rbSelectedText.AutoSize = true;
			this.rbSelectedText.Location = new Point(8, 34);
			this.rbSelectedText.Name = "rbSelectedText";
			this.rbSelectedText.Size = new Size(87, 17);
			this.rbSelectedText.TabIndex = 0;
			this.rbSelectedText.TabStop = true;
			this.rbSelectedText.Text = "&Selected text";
			this.rbSelectedText.UseVisualStyleBackColor = true;
			this.rbCurrentDocument.AutoSize = true;
			this.rbCurrentDocument.Checked = true;
			this.rbCurrentDocument.Location = new Point(8, 16);
			this.rbCurrentDocument.Name = "rbCurrentDocument";
			this.rbCurrentDocument.Size = new Size(109, 17);
			this.rbCurrentDocument.TabIndex = 4;
			this.rbCurrentDocument.TabStop = true;
			this.rbCurrentDocument.Text = "C&urrent document";
			this.rbCurrentDocument.UseVisualStyleBackColor = true;
			this.gbDirection.Controls.Add(this.rbBackward);
			this.gbDirection.Controls.Add(this.rbForward);
			this.gbDirection.Location = new Point(8, 167);
			this.gbDirection.Name = "gbDirection";
			this.gbDirection.Size = new Size(168, 58);
			this.gbDirection.TabIndex = 23;
			this.gbDirection.TabStop = false;
			this.gbDirection.Text = "Direction";
			this.rbBackward.AutoSize = true;
			this.rbBackward.Location = new Point(8, 33);
			this.rbBackward.Name = "rbBackward";
			this.rbBackward.Size = new Size(73, 17);
			this.rbBackward.TabIndex = 2;
			this.rbBackward.TabStop = true;
			this.rbBackward.Text = "&Backward";
			this.rbBackward.UseVisualStyleBackColor = true;
			this.rbForward.AutoSize = true;
			this.rbForward.Checked = true;
			this.rbForward.Location = new Point(8, 16);
			this.rbForward.Name = "rbForward";
			this.rbForward.Size = new Size(63, 17);
			this.rbForward.TabIndex = 1;
			this.rbForward.TabStop = true;
			this.rbForward.Text = "Forwar&d";
			this.rbForward.UseVisualStyleBackColor = true;
			this.gbOrigin.Controls.Add(this.rbEntireScope);
			this.gbOrigin.Controls.Add(this.rbFromCursor);
			this.gbOrigin.Location = new Point(184, 167);
			this.gbOrigin.Name = "gbOrigin";
			this.gbOrigin.Size = new Size(168, 58);
			this.gbOrigin.TabIndex = 22;
			this.gbOrigin.TabStop = false;
			this.gbOrigin.Text = "Origin";
			this.rbEntireScope.AutoSize = true;
			this.rbEntireScope.Checked = true;
			this.rbEntireScope.Location = new Point(8, 33);
			this.rbEntireScope.Name = "rbEntireScope";
			this.rbEntireScope.Size = new Size(84, 17);
			this.rbEntireScope.TabIndex = 2;
			this.rbEntireScope.TabStop = true;
			this.rbEntireScope.Text = "&Entire scope";
			this.rbEntireScope.UseVisualStyleBackColor = true;
			this.rbFromCursor.AutoSize = true;
			this.rbFromCursor.Location = new Point(8, 16);
			this.rbFromCursor.Name = "rbFromCursor";
			this.rbFromCursor.Size = new Size(80, 17);
			this.rbFromCursor.TabIndex = 1;
			this.rbFromCursor.TabStop = true;
			this.rbFromCursor.Text = "&From cursor";
			this.rbFromCursor.UseVisualStyleBackColor = true;
			this.panel1.Controls.Add(this.btCancel);
			this.panel1.Controls.Add(this.btReplaceAll);
			this.panel1.Controls.Add(this.btOk);
			this.panel1.Dock = DockStyle.Bottom;
			this.panel1.Location = new Point(0, 237);
			this.panel1.Name = "panel1";
			this.panel1.Size = new Size(360, 38);
			this.panel1.TabIndex = 24;
			this.btCancel.DialogResult = DialogResult.Cancel;
			this.btCancel.Location = new Point(277, 4);
			this.btCancel.Name = "btCancel";
			this.btCancel.Size = new Size(75, 25);
			this.btCancel.TabIndex = 29;
			this.btCancel.Text = "Cancel";
			this.btCancel.UseVisualStyleBackColor = true;
			this.btCancel.Click += new EventHandler(this.btCancel_Click);
			this.btReplaceAll.DialogResult = DialogResult.OK;
			this.btReplaceAll.Location = new Point(197, 4);
			this.btReplaceAll.Name = "btReplaceAll";
			this.btReplaceAll.Size = new Size(75, 25);
			this.btReplaceAll.TabIndex = 28;
			this.btReplaceAll.Text = "Replace &All";
			this.btReplaceAll.UseVisualStyleBackColor = true;
			this.btReplaceAll.Click += new EventHandler(this.btReplaceAll_Click);
			this.btOk.DialogResult = DialogResult.Yes;
			this.btOk.Location = new Point(117, 4);
			this.btOk.Name = "btOk";
			this.btOk.Size = new Size(75, 25);
			this.btOk.TabIndex = 27;
			this.btOk.Text = "OK";
			this.btOk.UseVisualStyleBackColor = true;
			this.btOk.Click += new EventHandler(this.btOk_Click);
			base.AcceptButton = this.btOk;
			base.AutoScaleDimensions = new SizeF(6f, 13f);
			base.AutoScaleMode = AutoScaleMode.Font;
			base.CancelButton = this.btCancel;
			base.ClientSize = new Size(360, 275);
			base.Controls.Add(this.panel1);
			base.Controls.Add(this.gbScope);
			base.Controls.Add(this.gbOrigin);
			base.Controls.Add(this.gbDirection);
			base.Controls.Add(this.gbOptions);
			base.Controls.Add(this.pnReplace);
			base.Controls.Add(this.pnFind);
			base.FormBorderStyle = FormBorderStyle.FixedToolWindow;
			base.Name = "DlgModalSearch";
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "Find Text";
			base.Load += new EventHandler(this.DlgModalSearch_Load);
			this.pnFind.ResumeLayout(false);
			this.pnFind.PerformLayout();
			this.pnReplace.ResumeLayout(false);
			this.pnReplace.PerformLayout();
			this.gbOptions.ResumeLayout(false);
			this.gbOptions.PerformLayout();
			this.gbScope.ResumeLayout(false);
			this.gbScope.PerformLayout();
			this.gbDirection.ResumeLayout(false);
			this.gbDirection.PerformLayout();
			this.gbOrigin.ResumeLayout(false);
			this.gbOrigin.PerformLayout();
			this.panel1.ResumeLayout(false);
			base.ResumeLayout(false);
		}
		public DlgModalSearch()
		{
			this.InitializeComponent();
		}
		private void ResizeControls()
		{
			if (this.baseOptionsHeight != 0 && this.baseHeight != 0)
			{
				this.laReplaceWith.Visible = this.isReplace;
				this.cbReplaceWith.Visible = this.isReplace;
				this.pnReplace.Visible = this.isReplace;
				this.btReplaceAll.Visible = this.isReplace;
				this.chbPromptOnReplace.Visible = this.isReplace;
				this.gbOptions.Height = (this.isReplace ? this.baseOptionsHeight : (this.baseOptionsHeight - this.chbPromptOnReplace.Height));
				this.gbScope.Height = this.gbOptions.Height;
				this.gbOptions.Top = (this.isReplace ? (this.pnReplace.Bottom + 3) : (this.pnFind.Bottom + 3));
				this.gbScope.Top = this.gbOptions.Top;
				this.gbDirection.Top = this.gbOptions.Bottom + 3;
				this.gbOrigin.Top = this.gbDirection.Top;
				this.btOk.Left = (this.isReplace ? (this.btReplaceAll.Left - this.btOk.Width - 5) : (this.btCancel.Left - this.btOk.Width - 5));
				base.Height = (this.IsReplace ? this.baseHeight : (this.baseHeight - this.chbPromptOnReplace.Height - this.pnReplace.Height));
				this.Text = (this.IsReplace ? "Find Text" : "Find Text");
			}
		}
		private void AddToHistory(IList List, string s)
		{
			if (s != string.Empty)
			{
				for (int i = List.IndexOf(s); i >= 0; i = List.IndexOf(s))
				{
					List.RemoveAt(i);
				}
				List.Insert(0, s);
			}
		}
		private void AddToHistory()
		{
			if (this.cbFindWhat.Text != string.Empty)
			{
				this.AddToHistory(this.cbFindWhat.Items, this.cbFindWhat.Text);
				this.cbFindWhat.SelectedIndex = 0;
			}
			if (this.isReplace && this.cbReplaceWith.Text != string.Empty)
			{
				this.AddToHistory(this.cbReplaceWith.Items, this.cbReplaceWith.Text);
				this.cbReplaceWith.SelectedIndex = 0;
			}
		}
		private void TextFound()
		{
			this.firstSearch = false;
			this.saveOptions = this.Options;
			this.saveText = this.cbFindWhat.Text;
		}
		private void UpdateSearchMode()
		{
			if (this.search != null)
			{
				this.search.SearchGlobal = (this.rbAllOpenDocuments.Checked || this.rbCurrentProject.Checked);
			}
			this.SearchShared = (this.search != null && this.search.SearchGlobal);
		}
		private void tbSearch_Enter(object sender, EventArgs e)
		{
			if (this.cbFindWhat.CanFocus)
			{
				this.cbFindWhat.Focus();
			}
		}
		private void DlgModalSearch_Load(object sender, EventArgs e)
		{
			base.ActiveControl = this.cbFindWhat;
			this.ResizeControls();
		}
		public void DoSearchReplace(bool isReplace)
		{
			this.AddToHistory();
			this.UpdateSearchMode();
			SearchManager.SharedSearch.IsReplace = isReplace;
		}
		public bool DoSearch()
		{
			SearchManager.SharedSearch.OnBeforeSearch(ref this.search, this.Options, this.cbFindWhat.Text);
			bool flag = false;
			this.DoSearchReplace(false);
			if (this.Search != null)
			{
				SearchOptions searchOptions = this.Options;
				if (!this.FirstSearch && !this.firstSearch && this.cbFindWhat.Text == this.saveText && searchOptions == this.saveOptions)
				{
					if ((searchOptions & SearchOptions.BackwardSearch) != SearchOptions.None)
					{
						flag = this.FindPrevious();
					}
					else
					{
						flag = this.FindNext();
					}
				}
				else
				{
					flag = this.Find(this.cbFindWhat.Text, searchOptions, this.GetExpression());
				}
				base.Close();
			}
			if (flag)
			{
				this.TextFound();
			}
			return flag;
		}
		public bool DoReplace()
		{
			bool flag = false;
			this.DoSearchReplace(true);
			if (this.Search != null)
			{
				SearchOptions searchOptions = this.Options;
				flag = this.Find(this.cbFindWhat.Text, searchOptions, this.GetExpression());
				if (flag)
				{
					this.TextFound();
				}
				base.Close();
			}
			return flag;
		}
		private void btOk_Click(object sender, EventArgs e)
		{
		}
		private RegexOptions GetRegexOptions(string text)
		{
			return (this.rbBackward.Checked ? RegexOptions.RightToLeft : RegexOptions.None) | ((!this.chbCaseSensitive.Checked) ? RegexOptions.IgnoreCase : RegexOptions.None) | ((text != null && (text.IndexOf("\\r") >= 0 || text.IndexOf("\\n") >= 0)) ? RegexOptions.Multiline : RegexOptions.None);
		}
		private bool IsEscapeChar(string s, int index)
		{
			bool flag = false;
			while (index > 0 && s[index - 1] == '\\')
			{
				if (s[index - 1] == '\\')
				{
					flag = !flag;
				}
				index--;
			}
			return flag;
		}
		private void RemoveChar(ref string s, char ch)
		{
			for (int i = s.Length - 1; i > 0; i--)
			{
				if (s[i] == ch && this.IsEscapeChar(s, i))
				{
					s = s.Remove(i - 1, 2);
				}
			}
		}
		private void ReplaceChar(ref string s, char ch, string replace)
		{
			for (int i = s.Length - 1; i > 0; i--)
			{
				if (s[i] == ch && this.IsEscapeChar(s, i))
				{
					s = s.Remove(i - 1, 2);
					if (replace != string.Empty)
					{
						s = s.Insert(i - 1, replace);
					}
				}
			}
		}
		private void FixCarriageReturn(ref string s)
		{
			this.ReplaceChar(ref s, 'r', string.Empty);
			this.ReplaceChar(ref s, 'n', "\\r\\n");
		}
		public Regex GetExpression()
		{
			Regex result = null;
			if (this.chbRegularExpressions.Checked)
			{
				try
				{
					string text = this.cbFindWhat.Text;
					this.FixCarriageReturn(ref text);
					result = new Regex(text, this.GetRegexOptions(this.cbFindWhat.Text));
				}
				catch (Exception exception)
				{
					result = null;
					ErrorHandler.Error(exception);
				}
			}
			return result;
		}
		protected override void OnFontChanged(EventArgs e)
		{
			base.OnFontChanged(e);
			this.ResizeControls();
		}
		protected void ReplaceChanged()
		{
			this.ResizeControls();
		}
		protected virtual bool FindPrevious()
		{
			return this.SearchShared ? SearchManager.SharedSearch.FindPrevious() : this.Search.FindPrevious();
		}
		protected virtual bool FindNext()
		{
			return this.SearchShared ? SearchManager.SharedSearch.FindNext() : this.Search.FindNext();
		}
		protected virtual bool Find(string text, SearchOptions options, Regex expression)
		{
			return this.SearchShared ? SearchManager.SharedSearch.Find(this.Search, text, options, expression) : this.Search.Find(text, options, expression);
		}
		protected virtual bool NeedReplaceCurrent(out Match match)
		{
			return this.SearchShared ? SearchManager.SharedSearch.NeedReplaceCurrent(out match) : this.Search.NeedReplaceCurrent(out match);
		}
		protected virtual bool ReplaceCurrent(string replaceWith, SearchOptions options, Match match)
		{
			return this.SearchShared ? SearchManager.SharedSearch.ReplaceCurrent(replaceWith, options, match) : this.Search.ReplaceCurrent(replaceWith, options, match);
		}
		protected virtual bool ReplaceAll(string text, string replaceWith, SearchOptions options, Regex expression, out int count)
		{
			bool flag;
			return this.SearchShared ? SearchManager.SharedSearch.ReplaceAll(this.Search, text, replaceWith, options, expression, out count, out flag) : this.Search.ReplaceAll(text, replaceWith, options, expression, out count, out flag);
		}
		protected void ShowNotFound()
		{
			this.ShowNotFound(this.Text);
			this.cbFindWhat.Focus();
		}
		protected virtual void ShowNotFound(string caption)
		{
			if (this.SearchShared)
			{
				SearchManager.SharedSearch.ShowNotFound(this.Search, caption);
			}
			else
			{
				this.Search.ShowNotFound(caption);
			}
		}
		public void Init()
		{
			this.baseOptionsHeight = this.gbOptions.Height;
			this.baseHeight = base.Height;
			this.firstSearch = true;
			this.saveOptions = SearchOptions.None;
			this.saveText = string.Empty;
		}
		private void btReplaceAll_Click(object sender, EventArgs e)
		{
		}
		private void tbUseReplace_Enter(object sender, EventArgs e)
		{
			if (this.cbFindWhat.CanFocus)
			{
				this.cbFindWhat.Focus();
			}
		}
		private void btCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}
	}
}
